package model.data;

import java.io.File;

import exceptions.FileException;


/**
 * 
 * @author Christelle SIAGO HAPPI 
 * class FileDescription : describe the
 *         properties of the file to send or to receive
 */

public class FileDescription {

	/**
	 * The maximum size of a file name
	 */
	final static public int MAX_SIZE = 50;
	/**
	 * The minimum size of a file name
	 */
	final static public int MIN_SIZE = 1;

	/**
	 * The file 
	 */
	private transient File myFile;

	/**
	 * 
	 * @param fileName
	 * @throws FileException
	 */
	public FileDescription(String fileName) throws FileException {
		if (FileDescription.checkNameFile((new File(fileName)).getName()) == false)
			throw new FileException("FileDescription invalid");

		this.myFile = new File(fileName);
	}

	/**
	 * create the description of the file to send or to receive
	 * @param fileName
	 */
	public FileDescription(FileDescription fileName) {
		this.myFile = new File(fileName.getAbsolutePath());
	}

	/**
	 * 
	 * @return The file name
	 */
	public final String getName() {
		return this.myFile.getName();
	}

	/**
	 * @return The file folder
	 */
	public final String getDirectory() {
		return this.myFile.getParent();
	}

	/**
	 * @return The absolute file fileName
	 */
	public final String getAbsolutePath() {
		return this.myFile.getAbsolutePath();
	}

	/**
	 * @return The file description
	 */
	public final File getFile() {
		return this.myFile;
	}

	/**
	 * @return The absolute file fileName
	 */
	public String toString() {
		return this.getAbsolutePath();
	}

	/**
	 * get the size of the file
	 */

	public int getSize(FileDescription fileName) {
		return getSize(fileName);
	}

	/**
	 * verify the file to send to the remote user
	 */
	public boolean equals(Object o) {
		return (this.getClass().isInstance(o) && this.getAbsolutePath().equals(
				((FileDescription) o).getAbsolutePath()));
	}

	/**
	 * Tests a filename
	 * 
	 * @param fileName
	 *            The file name
	 * @return true if check is succeed
	 */
	static public boolean checkNameFile(String fileName) {
		return (fileName != null
				&& fileName.length() >= FileDescription.MIN_SIZE && fileName
				.length() <= FileDescription.MAX_SIZE);
	}

}
